package stores;

import java.sql.Connection;
import models.Odontologo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Dao_connection {
	private Connection connection; 
	private static Dao_connection instancia;
	
	
	
	public static Dao_connection getInstancia() {
		if(instancia==null)
		{
			instancia= new Dao_connection();
		}
		return instancia;
	}

	private Dao_connection() {
		super();
	}

	public Connection getConnection()
	{
		
		try{
		
			if(connection == null || connection.isClosed())
			{
				try{
					String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
					String urldb = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=consultorioSeminario";
					String user = "ale1";
					String psw = "ale";
					Class.forName(driver);
					connection = DriverManager.getConnection(urldb,user,psw);
				} catch (SQLException e) {
					e.printStackTrace();
					return null;
				}catch (Exception e) {
					e.printStackTrace();
					return null;
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		return connection;
	}
	
	private void closeConnection ()
	{
		try {
		connection.close();
		}catch (Exception e) {
	
		}
	}
	
}
